package network

//HTTP请求数据包结构
type HttpReqData struct {
	Method         string //请求方法GET、POST、PUT、DELETE...
	URL            string //请求URL  /
	Version        string //HTTP协议版本  HTTP/1.1    HTTP/1.0
	Accept         string //Accept: */*
	Host           string //Host:
	Cache_Control  string //Cache-Control:no-cache
	Connection     string //Keep-Alive
	Refer          string //请求来源：Refer:
	User_Agent     string //客户端软件信息：User-Agent:
	Content_Type   string //Content-Type:
	Content_Length string //Content-Length:
	Content        string //Content
}

//HTTP响应数据包结构
type HttpRespData struct {
	Version   string            //HTTP协议版本  HTTP/1.1    HTTP/1.0
	StateCode string            //状态码
	StateName string            //状态短语
	Header    map[string]string //响应头
	Body      []byte            //响应正文
}

//HTTP请求数据包转字符串
func (req *HttpReqData) ToString() string {
	allStr := ""
	//组合状态行
	allStr += req.Method + " "
	allStr += req.URL + " "
	allStr += req.Version + "\r\n"
	//组合请求头
	allStr += "Accept:" + req.Accept + "\r\n"
	allStr += "Host:" + req.Host + "\r\n"
	allStr += "Cache-Control:" + req.Cache_Control + "\r\n"
	allStr += "Connection:" + req.Connection + "\r\n"
	allStr += "Refer:" + req.Refer + "\r\n"
	allStr += "User-Agent:" + req.User_Agent + "\r\n"
	if req.Method == "POST" || req.Method == "PUT" {
		allStr += "Content-Type:" + req.Content_Type + "\r\n"
	}
	allStr += "Content-Length:" + req.Content_Length + "\r\n"
	//组合请求正文
	allStr += "\r\n"
	allStr += req.Content

	return allStr
}

//获取附加数据包
var attdDef = ""

func GetAttd(n int) string {
	if attdDef == "" {
		for i := 0; i < 10; i++ {
			attdDef += "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" //100 * 10
		}
		attdDef += "012345678901234567890123" //24
	}
	var attd = ""
	for i := 0; i < n; i++ {
		attd += attdDef
	}
	return attd
}
